@extends('salesman.layouts.app')

@section('panel_content')

    <div class="card">
        <form id="sort_orders" action="" method="GET">
          <div class="card-header row gutters-5">
            <div class="col text-center text-md-left">
              <h5 class="mb-md-0 h6">{{ translate('Orders') }}</h5>
            </div>
              <div class="col-md-3 ml-auto">
                  <select class="form-control aiz-selectpicker" data-placeholder="{{ translate('Exec Status')}}" name="exec_status" onchange="sort_orders()">
                      <option value="">{{ translate('Exec Status')}}</option>
                      <option value="1" @isset($exec_status) @if($exec_status == '1') selected @endif @endisset>{{ translate('Exec Success')}}</option>
                      <option value="2" @isset($exec_status) @if($exec_status == '2') selected @endif @endisset>{{ translate('Exec Wait')}}</option>
                      <option value="3" @isset($exec_status) @if($exec_status == '3') selected @endif @endisset>{{ translate('Exec Err')}}</option>
                  </select>
              </div>
              <div class="col-md-3">
                <div class="from-group mb-0">
                    <input type="text" class="form-control" id="search" name="search" @isset($search) value="{{ $search }}" @endisset placeholder="{{ translate('Type Order code & hit Enter') }}">
                </div>
              </div>
          </div>
        </form>

        @if (count($orders) > 0)
            <div class="card-body p-3">
                <table class="table aiz-table mb-0">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>{{ translate('Order Code')}}</th>
                            <th data-breakpoints="lg">{{ translate('Shop')}}</th>
                            <th data-breakpoints="lg">{{ translate('Num. of Products')}}</th>
                            <th data-breakpoints="lg">{{ translate('Customer')}}</th>
                            <th data-breakpoints="md">{{ translate('Amount')}}</th>
                            <th data-breakpoints="md">{{ translate('Profit')}}</th>
                            <th data-breakpoints="lg">{{ translate('Exec Status')}}</th>
                            <th data-breakpoints="lg">{{ translate('Exec Time')}}</th>
                            <th data-breakpoints="lg">{{ translate('Exec Result')}}</th>
                            <th class="text-right">{{ translate('Options')}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($orders as $key => $item)
                            @php
                                $inputs = json_decode($item->inputs, 1);
                                if($inputs){
                                  $cart = $inputs['cart'];
                                }
                            @endphp
                            @if($inputs != null)
                                <tr>
                                    <td>
                                        {{ $key+1 }}
                                    </td>
                                    <td>
                                        <a href="#" onclick="">{{ $item->order_no }}</a>
                                    </td>
                                    <td>
                                       {{ $item->email }}
                                    </td>
                                    <td>
                                        {{ count($inputs['cart']) }}
                                    </td>
                                    <td>
                                        {{ $item->customer }}
                                    </td>
                                    <td>
                                        {{ single_price($item->subtotal) }}
                                    </td>
                                    <td>
                                        {{ translate('None') }}
                                    </td>
                                    <td>
                                    @if ($item->exec_status == '1')
                                            <span class="badge badge-inline badge-success">{{ translate('Exec Success')}}</span>
                                        @elseif ($item->exec_status == '2')
                                            <span class="badge badge-inline badge-warning">{{ translate('Exec Wait')}}</span>
                                        @elseif ($item->exec_status == '3')
                                            <span class="badge badge-inline badge-danger">{{ translate('Exec Err')}}</span>
                                        @endif
                                    </td>
                                    <td>
                                        {{ $item->cron_time }}
                                    </td>
                                    <td>
                                        {{ $item->job_exec_msg }}
                                    </td>
                                    <td>
                                        @if($item->exec_status != 1)
                                        <a href="#" class="btn btn-soft-danger btn-icon btn-circle btn-sm confirm-delete" data-href="{{route('pos.order_job_delete', $item->id)}}" title="{{ translate('Delete') }}">
                                            <i class="las la-trash"></i>
                                        </a>
                                        @endif
                                    </td>
                                </tr>
                            @endif
                        @endforeach
                    </tbody>
                </table>
                <div class="aiz-pagination">
                    {{ $orders->links() }}
              	</div>
            </div>
        @endif
    </div>

@endsection
@section('modal')
    @include('modals.delete_modal')
@endsection
@section('script')
    <script type="text/javascript">
        function sort_orders(el){
            $('#sort_orders').submit();
        }
    </script>
@endsection
